package models

import (
	"gorm.io/gorm"
	"order_srv/basic/config"
	"time"
)

// Operator 操作员信息表
type Operator struct {
	ID                  uint64         `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
	OperatorID          string         `gorm:"type:varchar(64);not null;uniqueIndex;comment:操作员ID" json:"operator_id"`
	OperatorName        string         `gorm:"type:varchar(100);not null;comment:操作员姓名" json:"operator_name"`
	OperatorType        int8           `gorm:"type:tinyint;not null;comment:操作员类型(agent-代理商,landlord-房东,admin-管理员)" json:"operator_type"`
	Phone               string         `gorm:"type:varchar(20);comment:手机号" json:"phone"`
	Email               string         `gorm:"type:varchar(100);comment:邮箱" json:"email"`
	Department          string         `gorm:"type:varchar(100);comment:部门" json:"department"`
	Position            string         `gorm:"type:varchar(100);comment:职位" json:"position"`
	MaxOrderCount       int32          `gorm:"default:0;comment:最大接单数量" json:"max_order_count"`
	CurrentOrderCount   int32          `gorm:"default:0;comment:当前接单数量" json:"current_order_count"`
	AcceptanceRate      float64        `gorm:"type:decimal(5,2);default:0.00;comment:接单率" json:"acceptance_rate"`
	AverageResponseTime int64          `gorm:"default:0;comment:平均响应时间(毫秒)" json:"average_response_time"`
	Status              int8           `gorm:"type:tinyint;default:1;comment:状态(1-正常,2-暂停,3-禁用)" json:"status"`
	LastActiveTime      *time.Time     `gorm:"type:timestamp;comment:最后活跃时间" json:"last_active_time"`
	CreatedAt           time.Time      `gorm:"autoCreateTime;index;comment:创建时间" json:"created_at"`
	UpdatedAt           time.Time      `gorm:"autoUpdateTime;comment:更新时间" json:"updated_at"`
	DeletedAt           gorm.DeletedAt `gorm:"index;comment:软删除时间" json:"deleted_at,omitempty"`
}

// CreateOperator 创建操作员
func (o *Operator) CreateOperator() error {
	return config.DB.Create(&o).Error
}

// UpdateOperator 更新操作员信息
func (o *Operator) UpdateOperator() error {
	return config.DB.Where("operator_id = ?", o.OperatorID).Updates(&o).Error
}
